package com.leyou.page.controller;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * 详情控制器
 */
@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     * 后端执行详情页
     * @return
     */
    @GetMapping("/item/{id}.html")
    public String showPageDetail(@PathVariable("id") Long id,Model model){
        //调用业务，获取详情页需要的数据
        Map<String,Object> resultMap = pageService.getPageDetail(id);

        //把数据存入Model中，让thymelead获取数据
        model.addAllAttributes(resultMap);

        //调整到thymeleaf模块
        //完整路径： resource/templates/item.html
        return "item";
    }



}
